home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12503 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.9 KB  |  123 lines

  1. Path: inforamp.net!ts13-11
  2. From: rmorin@inforamp.net (Randy Charles Morin)
  3. Newsgroups: comp.lang.c++
  4. Subject: OWL TEditSearch find-replace has incorrect behavior
  5. Date: Wed, 20 Mar 96 07:34:30 GMT
  6. Organization: MiddleWorld SoftWare
  7. Message-ID: <4iocet$n9v@sam.inforamp.net>
  8. NNTP-Posting-Host: ts34-09.tor.inforamp.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #4
  10.  
  11. Here's the correct behavior.
  12. This hasn't been excessively tested.
  13. I hope this helps someone.
  14. Of course, you needs to work on the message map also.
  15. I thought about encapsulating these changes,
  16. but I decided against further development in OWL
  17. until I've seen 5.0, 4.5 was a big disappointment.
  18.  
  19. --------
  20. void MWTextFileEditView::CmEditFind ()
  21. {
  22.      // INSERT>> Your code here.
  23.     if (!SearchCmd)
  24.     {
  25.         SearchCmd = CM_EDITFIND;
  26.         delete SearchDialog;
  27.         SearchDialog = new TFindDialog(this, SearchData);
  28.         SearchDialog->Create();
  29.     }
  30. }
  31.  
  32. void MWTextFileEditView::CmEditReplace ()
  33. {
  34.      // INSERT>> Your code here.
  35.     if (!SearchCmd)
  36.     {
  37.         SearchCmd = CM_EDITREPLACE;
  38.         delete SearchDialog;
  39.         SearchDialog = new TReplaceDialog(this, SearchData);
  40.         SearchDialog->Create();
  41.     }
  42. }
  43.  
  44.  
  45. void MWTextFileEditView::CmEditFindNext ()
  46. {
  47.      // INSERT>> Your code here.
  48.     if (SearchDialog)
  49.         SearchDialog->UpdateData();
  50.     SearchData.Flags |= FR_FINDNEXT;
  51.     DoSearch();
  52. }
  53.  
  54. void MWTextFileEditView::DoSearch()
  55. {
  56.   do {
  57. #if defined(BI_PLAT_WIN32)
  58.     unsigned long version = ::GetVersion();
  59.      if (version & 0x80000000L) {
  60.         if (GetApplication())
  61.           GetApplication()->PumpWaitingMessages();
  62.      }
  63. #endif
  64.     if (SearchData.Flags & FR_REPLACE)
  65.     {
  66.         uint startPos, endPos;
  67.         GetSelection(startPos, endPos);
  68.         char * szBuffer = new char [endPos-startPos+2];
  69.         GetSubText(szBuffer, startPos, endPos);
  70.         string strTemp = string(szBuffer);
  71.         if 
  72. (to_upper(strTemp).compare(to_upper(string(SearchData.FindWhat)))==0)
  73.           Insert(SearchData.ReplaceWith);
  74.     };
  75.  
  76.      if (Search(-1, SearchData.FindWhat, 
  77. bool(SearchData.Flags&FR_MATCHCASE),
  78.                     bool(SearchData.Flags&FR_WHOLEWORD),
  79.                     !(SearchData.Flags&FR_DOWN)) >= 0) {
  80.         if (SearchData.Flags & (/*FR_REPLACE|*/FR_REPLACEALL))
  81.           Insert(SearchData.ReplaceWith);
  82.      }
  83.      else {
  84.         if (SearchData.Flags & (FR_FINDNEXT|FR_REPLACE)) {
  85.           string errTemplate(GetModule()->LoadString(IDS_CANNOTFIND));
  86.           char  errMsg[81];
  87.           wsprintf(errMsg, errTemplate.c_str(), (const char 
  88. far*)SearchData.FindWhat);
  89.           TWindow* w = SearchDialog ? (TWindow*)SearchDialog : 
  90. (TWindow*)this;
  91.           w->MessageBox(errMsg, GetApplication()->GetName(),
  92.                              MB_OK | 
  93. MB_ICONEXCLAMATION | MB_TASKMODAL);
  94.         }
  95.         else if (SearchData.Flags & FR_REPLACEALL)
  96.           break;
  97.      }
  98.   } while (SearchData.Flags & FR_REPLACEALL);
  99. }
  100.  
  101. LRESULT MWTextFileEditView::EvFindMsg(WPARAM, LPARAM lParam)
  102. {
  103.   PRECONDITION(SearchDialog);
  104.  
  105.   SearchDialog->UpdateData(lParam);
  106.   if (SearchData.Flags & FR_DIALOGTERM)
  107.      SearchCmd = 0;
  108.  
  109.   else
  110.      DoSearch();
  111.   return 0;
  112. }
  113.  
  114. ----------
  115.  
  116.  
  117. Agrivar
  118.  
  119. aka     Randy Charles Morin
  120.     MiddleWorld SoftWare
  121.     Canada: 1-800-363-3780
  122.     Other:    905-279-2087
  123.